package com.stark.wechat.handler;

import javax.servlet.http.HttpServletRequest;

import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * error 处理器。
 * <p>代理所有 error-page 处理。
 * @author mengbin
 * @since 1.1.0
 * @version 1.0.0, 2017/9/22
 */
@Controller
public class ErrorHandler {
	@RequestMapping("/error")
	public ModelAndView handle(HttpServletRequest request) {
		Integer errcode = (Integer) request.getAttribute("javax.servlet.error.status_code");
		String errmsg = HttpStatus.valueOf(errcode).getReasonPhrase();
		
		ModelAndView mav = new ModelAndView("info/error");
		mav.addObject("errcode", errcode);
		mav.addObject("errmsg", errmsg);
		mav.addObject("msg", errcode + " - " + errmsg);
		return mav;
	}
}
